/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import framework.GameObject;
import framework.Key;
import framework.Screen;
import framework.Util;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;

/**
 *
 * @author edilson
 */
public class Inimigo_ extends GameObject {

    public static final int TIPE_1 = 1;
    public static final int TIPE_2 = 2;
    public static final int TIPE_3 = 3;
    int xm[];
    int ym[];
    int xm1;
    int ym1;
    int m;
    private int tipe;
    int speed;

    public Inimigo_(int tipe) {

        xm = new int[4];
        ym = new int[4];


        if (tipe == TIPE_1) {
            this.image = Util.loadImage(Global.IMG_INIMIGO_1);

            xm[0] = Screen.getWidth() / 4;
            ym[0] = (Screen.getHeight() / 4) * 3;

            xm[1] = (Screen.getWidth() / 4) * 3;
            ym[1] = (Screen.getHeight() / 4);

            xm[2] = (Screen.getWidth() / 4) * 3;
            ym[2] = (Screen.getHeight() / 4) * 3;

            xm[3] = (Screen.getWidth() / 4);
            ym[3] = (Screen.getHeight() / 4);

        } else if (tipe == TIPE_2) {
            this.image = Util.loadImage(Global.IMG_INIMIGO_2);
        } else if (tipe == TIPE_3) {
            this.image = Util.loadImage(Global.IMG_INIMIGO_3);
        }

        this.tipe = tipe;

        this.x = Screen.getWidth() / 2;
        this.y = -10;
        this.width = image.getWidth(null);
        this.height = image.getHeight(null);

        m = 0;

        xm1 = xm[m];
        ym1 = ym[m];

        speed = 8;
        speedY = speed;
        speedX = speed;


    }

    @Override
    public void update() {





        if (((x - xm[m] < 8) || ((x - xm[m] > 8))) && ((y - ym[m] < 10) || ((y - ym[m] > 10)))) {
            m++;
            if (m == 4) {
                m = 0;
            }
        }
        xm1 = xm[m];
        ym1 = ym[m];




        if (this.tipe == TIPE_1) {


            System.out.println("X= " + x + " - " + xm[m]);
            System.out.println("Y= " + y + " - " + ym[m]);
            System.out.println(m);


            if (x < xm1) {
                speedX = speedX;
            } else if (x > xm1) {
                speedX = speedX * -1;
            } else {
                speedX = 0;
            }

            if (y < ym1) {
                speedY = speedY;
            } else if (y > ym1) {
                speedY = speedY * -1;
            } else {
                speedY = 0;
            }




        } else if (this.tipe == TIPE_2) {



            speedY = 3;




        } else if (this.tipe == TIPE_3) {
            speedY = 5;
        }


        if (x <= 0) {
            x = 0;
        }

        if (x >= Screen.getWidth() - image.getWidth(null)) {
            x = Screen.getWidth() - image.getWidth(null);
        }


//        if(y <= 0)
//            y=0;

        if (y >= Screen.getHeight() - image.getHeight(null)) {
            y = Screen.getHeight() - image.getHeight(null);
        }




        // movendo a barra
        x += speedX;
        y += speedY;

    }

    @Override
    public void paint(Graphics g) {

        if (this.visible) {
            g.drawImage(image, x, y, null);
        }



        g.setColor(Color.WHITE);

        for (int i = 0; i < 4; i++) {
            g.drawOval(xm[i], ym[i], 10, 10);

        }



    }
}
